package au.pavel.Tests;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;

import au.pavel.Units.IAttackObject;
import au.pavel.Units.IDestroyableObject;
import au.pavel.damage.IAttack;
import au.pavel.damageCalculator.IDamageCalculator;
import au.pavel.damageController.DamageCalculator;
import au.pavel.damageController.DamageController;

public class DamageTests {

	IAttackObject _mockAttackObject;
	IAttack _mockAttack;
	IDestroyableObject _mockDestryableObject;
	IDamageCalculator _mockCalculator;
	DamageController _controller;
	DamageCalculator _calculator;


	@Before
	public void setupTest() {

		_mockAttackObject = mock(IAttackObject.class);
		_mockAttack = mock(IAttack.class);
		_mockDestryableObject = mock(IDestroyableObject.class);
		_mockCalculator = mock(IDamageCalculator.class);
		_controller = new DamageController();
		_calculator = new DamageCalculator(_mockCalculator);
	}

	@Test
	public void calculateDamageTest() throws Exception{
		stub(_mockAttackObject.get_pureAttack()).toReturn(5f);
		stub(_mockAttack.get_damageBonus()).toReturn(1.5f);
		
		float damage = _mockAttackObject.get_pureAttack() * _mockAttack.get_damageBonus();
		
		stub(_mockCalculator.calculateDamage(_mockAttackObject, _mockAttack)).toReturn(damage);

		float value = _calculator.CalculateDamage(_mockAttackObject, _mockAttack);
		
		assertEquals(7,5d, (double)value);
	}
	
	@Test
	public void applyDamagetest() throws Exception{
		stub(_mockDestryableObject.get_totalHealth()).toReturn(10f);
		stub(_mockDestryableObject.get_actualHealth()).toReturn(2.5f);
		
		_controller.applyDamage(7.5f, _mockDestryableObject);
		
		float expectedHealth = _mockDestryableObject.get_totalHealth() - 7.5f;
		
		float value = _mockDestryableObject.get_actualHealth();
		
		assertTrue(expectedHealth == value);
	}
}
